package com.gf.test1;

import redis.clients.jedis.Jedis;

public class Test2 {

	public static void main(String[] args) {
		try {
			Jedis jedis = new Jedis("10.2.130.228", 6379);
			
			//System.out.println("新增key001,value001键值对："+jedis.set("key001", "value001")); 
	        //System.out.println("判断key001是否存在："+jedis.exists("key001"));
			// 设置 key001的过期时间
			System.out.println("设置 key001的过期时间为5秒:"+jedis.set("key001", "asdf", "NX", "EX", 5));
	        //System.out.println("设置 key001的过期时间为5秒:"+jedis.expire("key001", 5));
	        System.out.println("判断key001是否存在："+jedis.exists("key001"));
	        
	        System.out.println("--------------");
	        Thread.sleep(2000); 
	        
	        // 查看某个key的剩余生存时间,单位【秒】.永久生存或者不存在的都返回-1
	        System.out.println("查看key001的剩余生存时间："+jedis.ttl("key001"));
	        // 移除某个key的生存时间
	        //System.out.println("移除key001的生存时间："+jedis.persist("key001"));
	        //System.out.println("查看key001的剩余生存时间："+jedis.ttl("key001"));
	        
	        // 查看key所储存的值的类型
	        System.out.println("查看key所储存的值的类型："+jedis.type("key001"));
	        System.out.println("查看key所储存的值："+jedis.get("key001"));
	        
	        System.out.println("--------------");
	        Thread.sleep(4000);
	        //System.out.println("新增key001,value001键值对："+jedis.set("key001", "value001")); 
	        System.out.println("判断key001是否存在："+jedis.exists("key001"));
	        System.out.println("查看key所储存的值："+jedis.get("key001"));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
